package dao.impl;

import dao.FileClassDao;
import domian.FileClass;
import domian.FileClassName;
import utils.BaseDAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class FileClassDaoImpl implements FileClassDao {



    @Override
    public List<FileClass> findAllFileClass() {
        List<FileClass> fileClassList = new ArrayList<>();
        Connection conn = BaseDAO.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from file_classify";
        try {
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            FileClass fileClass =null;
            while (rs.next()) {
                int id = rs.getInt("id");
                String oneClass = rs.getString("f_title");
                Integer twoClass = rs.getInt("f_cid");
                fileClass = new FileClass(id,oneClass,twoClass);
                fileClassList.add(fileClass);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            BaseDAO.close(conn, ps, rs);
        }
        return fileClassList;
    }
}
